#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    bool lemonadeChange(vector<int>& bills) {
        int five = 0, ten = 0;
        for (int bill : bills) {
            if (bill == 5)
                five++;
            else if (bill == 10)
                if (five)
                    five--, ten++;
                else
                    return false;
            else {
                if (ten && five)
                    ten--, five--;
                else if (five == 0)
                    return false;
                else if (five < 3)
                    return false;
                else
                    five -= 3;
            }
        }
        return true;
    }
};